<?php
/**
* Author	: TRUONG KIM PHUNG
* Class		: Promotion
* Description
	* Manage Promotion
	* Get
	* Add
	* Update
	* Delete
* Contact	:
	- Email : truongkimphung1982@gmail.com
	- Y!	: truongkimphung1982
	- Skype	: truongkimphung1982
**/
class Promotion extends Ecore_Db {
	var $cache;
	var $clear;
	public function __construct() {
		$this->cache = new Ecore_Cache();
		$this->clear = $this->cache->clear;
	}	
	/**
	 * GET INFORMATION PROMOTION BY ID
	 * @PARAM
			- $intPromotionId
	 * @RESULT
			- Array | NULL
	 */
	public function get($intPromotionId) {
		try {			
			$this->prepare('call promotions_get(?)');
			$this->bindParam(1 , $intPromotionId	, PDO::PARAM_INT, 11);			
			$arrResult 	= $this->fetchAll();
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exception $e) {
			Ecore_Function::logDb('Promotion::get - ' . $e->getMessage());
		}
	}
	/**
	 * GET FEATURE LIST
	 * @PARAM
			- $intCategoryId
			- $intSubId
			- $intOffset
			- $intLimit
			- $intTotal
	 * @RESULT
			- Array | NULL
	 */
	public function getFeature($intCategoryId, $intSubId, $intOffset, $intLimit, &$intTotal=0) {		
		try {
			$this->prepare('call promotions_getall_feature(?,?,?,?)');
			$this->bindParam(1 , $intCategoryId	, PDO::PARAM_INT, 11);			
			$this->bindParam(2 , $intSubId		, PDO::PARAM_INT, 11);			
			$this->bindParam(3 , $intOffset		, PDO::PARAM_INT, 11);			
			$this->bindParam(4 , $intLimit		, PDO::PARAM_INT, 4);			
			$arrResult 	= $this->fetchAll();			
			$intTotal = isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Ecore_Function::logDb('Promotion::getFeature - ' . $e->getMessage());
		}
	}
}